package HashMap;

import java.util.*;

public class Test2 {
    public static void main(String[] args) {
        //创建单列集合，记录投票结果
        ArrayList<String> list=new ArrayList();
        Random r=new Random();
        String[] arr={"A","B","C","D"};
        for (int i = 0; i < 80; i++) {
            int index=r.nextInt(arr.length);
            list.add(arr[index]);
            System.out.println(arr[index]);
        }

        HashMap<String,Integer> map=new HashMap();
        for (String key : list) {
            if(map.containsKey(key)){
                //存在
                int count=map.get(key);
                count++;
                map.put(key,count);
            }
            else{
                //不存在
                map.put(key,1);
            }
        }
        System.out.println(map);
        //求最大值
        int max=0;
        Set<Map.Entry<String, Integer>> entries = map.entrySet();
        for (Map.Entry<String, Integer> entry : entries) {
            int value=entry.getValue();
            if(value>max){
                max=value;
            }
        }
        //打印最大值
        for (Map.Entry<String, Integer> entry : entries) {
            int value=entry.getValue();
            if(max==value){
                System.out.println(entry.getKey());
            }
        }


    }
}
